<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <script src="./iscroll.js">
    </script>
    <style>
        html,
        body {
            height: 100%;
        }

        * {
            margin: 0;
            padding: 0;
        }

        .wrap {
            width: 100%;
            height: 100%;
            background: #fff;
            overflow: hidden;
            position: relative;
        }

        .content {
            width: 100%;
            height: 1000px;
            background: -webkit-linear-gradient(left top, red, green);
            position: relative;
            z-index: 2;
        }

        #up {
            position: absolute;
            left: 0;
            top: 0;
            width: 100%;
            height: 50px;
            z-index: 1;
        }
    </style>
</head>

<body>
    <div class="wrap">
        <div class="content">

        </div>
        <div id="up">下拉刷新</div>
        <!-- <div class="down"></div> -->
    </div>
</body>
<script>
    window.onload = function () {
        let up = document.getElementById('up');
        let scrollBeforeRelease = 0;
        let iscroll = new IScroll('.wrap', {
            momentum: false, //开启物理引擎
            probeType: 2 //检测滚动类型1,延时 2,只检测下拉 3,下拉回位都检测
        })
        console.log(iscroll)
        iscroll.on('scrollStart', function () {
            iscroll.endTime = 0;
            scrollBeforeRelease = 0;
            iscroll.minScrollY =100;
            iscroll.on('scroll', fnScroll)
        })

        function fnScroll() {
            let y = iscroll.y;
            if (iscroll.endTime == 0) {
                if (y > 100) {
                    up.innerHTML = '松开刷新'
                } else {
                    up.innerHTML = '下拉刷新'
                }
            } else {
                
                iscroll.off('scroll', fnScroll)
                if (y > 100) {
                    up.innerHTML = '正在加载'
                } else {
                    up.innerHTML = '下拉刷新'
                }

            }
         
            console.log(y)

            scrollBeforeRelease = scrollBeforeRelease > y ? scrollBeforeRelease : y;

        }
        iscroll.on('scrollEnd', function () {
            if (scrollBeforeRelease > 100) {
                console.log(1)
            } else {
                console.log(2)
            }
        })
    }
</script>

</html>